import request from "@/utils/request";
import type { ResponseData, PageData } from "@/api/type";
import type { RoleInfo, PermissionResult, RolePermission } from "@/api/role/type";

enum API {
    ROLE_PAGE_URL = "/admin/acl/role/",
    ROLE_ADD_URL = "/admin/acl/role/save",
    ROLE_UPDATE_URL = "/admin/acl/role/update",
    ROLE_DELETE_URL = "/admin/acl/role/remove/",
    ROLE_Batch_DELETE_URL = "/admin/acl/role/batchRemove",
    ROLE_DO_ASSIGN_URL = "/admin/acl/permission/doAssignAcl",
    ROLE_TO_ASSIGN_URL = "/admin/acl/permission/toAssign/",
    PERMISSION_LIST_URL = "/admin/acl/permission",
    PERMISSION_SAVE_URL = "/admin/acl/permission/save",
    PERMISSION_UPDATE_URL = "/admin/acl/permission/update",
    PERMISSION_DELETE_URL = "/admin/acl/permission/remove/",
}

const reqRolePage = (page: number, limit: number, roleName: string) => request.get<String, ResponseData<PageData<RoleInfo>>>(API.ROLE_PAGE_URL + `${page}/${limit}` + (roleName ? `?roleName=${roleName}` : ""))
const reqRoleAdd = (data: RoleInfo) => request.post<String, ResponseData<String>>(API.ROLE_ADD_URL, data)
const reqRoleUpdate = (data: RoleInfo) => request.put<String, ResponseData<String>>(API.ROLE_UPDATE_URL, data)
const reqRoleDelete = (id: number) => request.delete<String, ResponseData<String>>(API.ROLE_DELETE_URL + id)
const reqRoleBatchDelete = (ids: number[]) => request.delete<String, ResponseData<String>>(API.ROLE_Batch_DELETE_URL, { data: ids })
const reqRoleDoAssign = (data: RolePermission) => request.post<String, ResponseData<any>>(API.ROLE_DO_ASSIGN_URL, data)
const reqRoleToAssign = (id: number) => request.get<String, ResponseData<PermissionResult>>(API.ROLE_TO_ASSIGN_URL + id)
const reqPermissionList = () => request.get<String, ResponseData<PermissionResult[]>>(API.PERMISSION_LIST_URL)
const reqPermissionSave = (data: PermissionResult) => request.post<String, ResponseData<String>>(API.PERMISSION_SAVE_URL, data)
const reqPermissionUpdate = (data: PermissionResult) => request.put<String, ResponseData<String>>(API.PERMISSION_UPDATE_URL, data)
const reqPermissionDelete = (id: number) => request.delete<String, ResponseData<String>>(API.PERMISSION_DELETE_URL + id)

export {
    reqRolePage,
    reqRoleAdd,
    reqRoleUpdate,
    reqRoleDelete,
    reqRoleBatchDelete,
    reqRoleDoAssign,
    reqRoleToAssign,
    reqPermissionList,
    reqPermissionSave,
    reqPermissionUpdate,
    reqPermissionDelete,
}
